#include "00_04_01_simulate_data.h"

/*创建采集模拟数据的线程*/
void *collect_data(void *arg)
{
	data_t tmp_data;			//创建结构体
	struct tm *ptm = NULL;		//定义时间结构体

	srand(time(NULL)); 			//产生随机数种子
	
	while(1)
	{
		tmp_data.co2_value = (rand() % 10000 + 1) / 100.0;    //对随机数进行处理
		tmp_data.pm2_5_value = (rand() % 10000 + 1) / 100.0;
		tmp_data.h2_value = (rand() % 10000 + 1) / 100.0;
		tmp_data.ch4_value = (rand() % 10000 + 1) / 100.0;
		time(&tmp_data.dt);

		ptm = localtime(&tmp_data.dt);						//获得时间
		printf("================= %04d-%02d-%02d %02d:%02d:%02d ===========================\n",				//打印数据与时间
				ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
		printf("CH:%2lf\n", tmp_data.ch4_value);
		printf("CO2:%2lf\n", tmp_data.co2_value);
		printf("H2:%2lf\n", tmp_data.h2_value);
		printf("PM2_5:%2lf\n", tmp_data.pm2_5_value);
		sleep(1);
	}
	
	return NULL;


}
